<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<script type="text/javascript">
	$('#addTKpYushouBtn').linkbutton({   
	    iconCls: 'icon-add'  
	});  
	$('#delTKpYushouBtn').linkbutton({   
	    iconCls: 'icon-remove'  
	}); 
	$('#addTKpYushouBtn').bind('click', function(){   
 		 var tr =  $("#add_tKpYushou_table_template tr").clone();
	 	 $("#add_tKpYushou_table").append(tr);
	 	 resetTrNum('add_tKpYushou_table');
	 	 return false;
    });  
	$('#delTKpYushouBtn').bind('click', function(){   
      	$("#add_tKpYushou_table").find("input:checked").parent().parent().remove();   
        resetTrNum('add_tKpYushou_table'); 
        return false;
    }); 
    $(document).ready(function(){
        countby1();
    	$(".datagrid-toolbar").parent().css("width","auto");
    	if(location.href.indexOf("load=detail")!=-1){
			$(":input").attr("disabled","true");
			$(".datagrid-toolbar").hide();
		}

    });

    function countby1() {
        var orQty = 0;
        var cpTiji = 0;
        var count = 0;


        $tbody = $("#add_tKpYushou_table");
        $tbody.find('>tr').each(function(i) {
            orQty = 0;
            cpTiji = 0;
            count = 0;
            var $by1;
            $(':input, select,button,a', this).each(function () {
                var $this = $(this), validtype_str = $this.attr('validType'), name = $this.attr('name'),
                    id = $this.attr('id'), onclick_str = $this.attr('onclick'), val = $this.val() ,value = $this.attr('value');
                value = 1*value;
                if (name.indexOf("ysJine") >= 0 ) {
                    if(value>0){
                        orQty = 1* value;
                    }
                }
                if (name.indexOf("daxie") >= 0 ) {
                    $by1 = $this;
                }
            });
            count =  smalltoBIG(orQty)  ;
            $by1.attr("value",count);

        });
    }
    function smalltoBIG(smallID)
    {
        var aNum=smallID;
        var n=aNum;
        var fraction = ['角', '分'];
        var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
        var unit = [ ['元', '万', '亿'], ['', '拾', '佰', '仟']  ];
        var head = n < 0? '欠': '';
        n = Math.abs(n);

        var s = '';

        for (var i = 0; i < fraction.length; i++)
        {
            s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
        }
        s = s || '整';
        n = Math.floor(n);

        for (var i = 0; i < unit[0].length && n > 0; i++)
        {
            var p = '';
            for (var j = 0; j < unit[1].length && n > 0; j++)
            {
                p = digit[n % 10] + unit[1][j] + p;
                n = Math.floor(n / 10);
            }
            s = p.replace(/(零.)*零$/, '').replace(/^$/, '零')  + unit[0][i] + s;
        }
        //return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
        bigID=head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
        return bigID;
    }

</script>
<div style="padding: 3px; height: 25px;width:auto;" class="datagrid-toolbar">
	<a id="addTKpYushouBtn" href="#">添加</a> <a id="delTKpYushouBtn" href="#">删除</a> 
</div>
<table border="0" cellpadding="2" cellspacing="0" id="tKpYushou_table">
	<tr bgcolor="#E6E6E6">
		<td align="center" bgcolor="#EEEEEE" style="width: 25px;">序号</td>
		<td align="center" bgcolor="#EEEEEE" style="width: 25px;">操作</td>
		<td align="left" bgcolor="#EEEEEE" style="width: 126px;">
			产品
		</td>
				  <td align="left" bgcolor="#EEEEEE" style="width: 126px;">
						来源
				  </td>
				  <td align="left" bgcolor="#EEEEEE" style="width: 126px;">
						金额
				  </td>
				  <%--<td align="left" bgcolor="#EEEEEE" style="width: 126px;">--%>
						<%--备注--%>
				  <%--</td>--%>
		<td align="left" bgcolor="#EEEEEE" style="width: 126px;">
			大写金额
		</td>
	</tr>
	<tbody id="add_tKpYushou_table">
	<c:if test="${fn:length(tKpYushouList)  <= 0 }">
			<tr>
				<td align="center"><div style="width: 25px;" name="xh">1</div></td>
				<td align="center"><input style="width:20px;"  type="checkbox" name="ck"/></td>
					<input name="tKpYushouList[0].id" type="hidden"/>
					<input name="tKpYushouList[0].createName" type="hidden"/>
					<input name="tKpYushouList[0].createBy" type="hidden"/>
					<input name="tKpYushouList[0].createDate" type="hidden"/>
					<input name="tKpYushouList[0].updateName" type="hidden"/>
					<input name="tKpYushouList[0].updateBy" type="hidden"/>
					<input name="tKpYushouList[0].updateDate" type="hidden"/>
					<input name="tKpYushouList[0].sysOrgCode" type="hidden"/>
					<input name="tKpYushouList[0].sysCompanyCode" type="hidden"/>
					<input name="tKpYushouList[0].bpmStatus" type="hidden"/>
					<input name="tKpYushouList[0].ysType" type="hidden"/>
					<input name="tKpYushouList[0].cusCode" type="hidden"/>
					<input name="tKpYushouList[0].cusName" type="hidden"/>
					<input name="tKpYushouList[0].gdCode" type="hidden"/>
					<input name="tKpYushouList[0].gdName" type="hidden"/>
					<input name="tKpYushouList[0].gdDaaima" type="hidden"/>
					<%--<input name="tKpYushouList[0].by1" type="hidden"/>--%>
					<input name="tKpYushouList[0].by2" type="hidden"/>
					<input name="tKpYushouList[0].by3" type="hidden"/>
					<input name="tKpYushouList[0].by4" type="hidden"/>
					<input name="tKpYushouList[0].by5" type="hidden"/>
					<input name="tKpYushouList[0].skid" type="hidden"/>
				<td align="left">
					<t:dictSelect field="tKpYushouList[0].by1" type="list"   typeGroupCode="kp_cp"  defaultVal="${tKpYushouPage.by1}" hasLabel="false"  title="产品"></t:dictSelect>
					<label class="Validform_label" style="display: none;">产品</label>
				</td>

				  <td align="left">
							<t:dictSelect field="tKpYushouList[0].ysFangshi" type="list"   typeGroupCode="ys_fangshi"  defaultVal="${tKpYushouPage.ysFangshi}" hasLabel="false"  title="收款来源"></t:dictSelect>
					  <label class="Validform_label" style="display: none;">来源</label>
					</td>
				  <td align="left">
					  	<input name="tKpYushouList[0].ysJine" maxlength="32" type="text" oninput="countby1()" class="inputxt"  style="width:120px;"  ignore="ignore" >
					  <label class="Validform_label" style="display: none;">金额</label>
					</td>
				  <%--<td align="left">--%>
					  	<%--<input name="tKpYushouList[0].ysRemark" maxlength="32" type="text" class="inputxt"  style="width:120px;"  ignore="ignore" >--%>
					  <%--<label class="Validform_label" style="display: none;">备注</label>--%>
					<%--</td>--%>

				<td align="left">
					<input name="tKpYushouList[0].daxie" maxlength="32" type="text" class="inputxt"  style="width:120px;"  ignore="ignore" >
					<label class="Validform_label" style="display: none;">大写</label>
				</td>

   			</tr>
	</c:if>
	<c:if test="${fn:length(tKpYushouList)  > 0 }">
		<c:forEach items="${tKpYushouList}" var="poVal" varStatus="stuts">
			<tr>
				<td align="center"><div style="width: 25px;" name="xh">${stuts.index+1 }</div></td>
				<td align="center"><input style="width:20px;"  type="checkbox" name="ck" /></td>
						<input name="tKpYushouList[${stuts.index }].id" type="hidden" value="${poVal.id }"/>
						<input name="tKpYushouList[${stuts.index }].createName" type="hidden" value="${poVal.createName }"/>
						<input name="tKpYushouList[${stuts.index }].createBy" type="hidden" value="${poVal.createBy }"/>
						<input name="tKpYushouList[${stuts.index }].createDate" type="hidden" value="${poVal.createDate }"/>
						<input name="tKpYushouList[${stuts.index }].updateName" type="hidden" value="${poVal.updateName }"/>
						<input name="tKpYushouList[${stuts.index }].updateBy" type="hidden" value="${poVal.updateBy }"/>
						<input name="tKpYushouList[${stuts.index }].updateDate" type="hidden" value="${poVal.updateDate }"/>
						<input name="tKpYushouList[${stuts.index }].sysOrgCode" type="hidden" value="${poVal.sysOrgCode }"/>
						<input name="tKpYushouList[${stuts.index }].sysCompanyCode" type="hidden" value="${poVal.sysCompanyCode }"/>
						<input name="tKpYushouList[${stuts.index }].bpmStatus" type="hidden" value="${poVal.bpmStatus }"/>
						<input name="tKpYushouList[${stuts.index }].ysType" type="hidden" value="${poVal.ysType }"/>
						<input name="tKpYushouList[${stuts.index }].cusCode" type="hidden" value="${poVal.cusCode }"/>
						<input name="tKpYushouList[${stuts.index }].cusName" type="hidden" value="${poVal.cusName }"/>
						<input name="tKpYushouList[${stuts.index }].gdCode" type="hidden" value="${poVal.gdCode }"/>
						<input name="tKpYushouList[${stuts.index }].gdName" type="hidden" value="${poVal.gdName }"/>
						<input name="tKpYushouList[${stuts.index }].gdDaaima" type="hidden" value="${poVal.gdDaaima }"/>
						<%--<input name="tKpYushouList[${stuts.index }].by1" type="hidden" value="${poVal.by1 }"/>--%>
						<input name="tKpYushouList[${stuts.index }].by2" type="hidden" value="${poVal.by2 }"/>
						<input name="tKpYushouList[${stuts.index }].by3" type="hidden" value="${poVal.by3 }"/>
						<input name="tKpYushouList[${stuts.index }].by4" type="hidden" value="${poVal.by4 }"/>
						<input name="tKpYushouList[${stuts.index }].by5" type="hidden" value="${poVal.by5 }"/>
						<input name="tKpYushouList[${stuts.index }].skid" type="hidden" value="${poVal.skid }"/>
				<td align="left">
					<t:dictSelect field="tKpYushouList[${stuts.index }].by1" type="list"   typeGroupCode="kp_cp"  defaultVal="${poVal.by1 }" hasLabel="false"  title="产品"></t:dictSelect>
					<label class="Validform_label" style="display: none;">产品</label>
				</td>
				<td align="left">
							<t:dictSelect field="tKpYushouList[${stuts.index }].ysFangshi" type="list"    typeGroupCode="ys_fangshi"  defaultVal="${poVal.ysFangshi }" hasLabel="false"  title="收款来源"></t:dictSelect>
					  <label class="Validform_label" style="display: none;">来源</label>
				   </td>
				   <td align="left">
					  	<input name="tKpYushouList[${stuts.index }].ysJine" maxlength="32"  type="text"  class="inputxt"  style="width:120px;"  ignore="ignore"  value="${poVal.ysJine }"/>
					  <label class="Validform_label" style="display: none;">金额</label>
				   </td>
				   <%--<td align="left">--%>
					  	<%--<input name="tKpYushouList[${stuts.index }].ysRemark" maxlength="32" type="text" class="inputxt"  style="width:120px;"  ignore="ignore"  value="${poVal.ysRemark }"/>--%>
					  <%--<label class="Validform_label" style="display: none;">备注</label>--%>
				   <%--</td>--%>
				<td align="left">
					<input name="tKpYushouList[${stuts.index }].daxie" maxlength="32" type="text" class="inputxt"  style="width:120px;"  ignore="ignore" >
					<label class="Validform_label" style="display: none;">大写</label>
				</td>
   			</tr>
		</c:forEach>
	</c:if>	
	</tbody>
</table>
